﻿<template>
    <div v-cloak class="h100 hidden-x" style="background-color: #F7F7F8; ">
        <component is="style" />
        <div v-for="x in menuList">
            <div style="font-size:12px;padding:4px 16px;color:#888;">{{x.name}}</div>
            <van-grid :column-num="4" class="bg-white" :border="false">
                <van-grid-item v-for="c in x.children" icon-prefix="tn-icon" :icon="c.icon" :text="c.name" :badge="!!c.badge?c.badge:''" :url="getUrl(c)" v-on:click="itemclick(c)"></van-grid-item>
            </van-grid>
        </div>
    </div>
</template>
<script>
    module = (function (hxt) {
        return {
            name: 'userinfo',
            data: function () {
                return {
                    optor: hxt.store.optor,
                    browser: hxt.wxBrowser(), // 1：手机微信；4：小程序
                    menuList: []
                };
            },
            computed: {

            },
            activated: function () {

            },
            mounted: function () {
                this.$parent.showHeader = true;
                this.loadMenu();
                
                var _this = this;
                if (!_this.optor.openId) {
                    this.$parent.sdkAdd = true;
                    return
                    window.location.replace("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7c055a436d4ca86d&redirect_uri=http%3A%2F%2Fdevelopers.weixin.qq.com&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect");
                };

            },
            methods: {
                loadMenu: function () {
                    var _this = this, wxMenus = _this.optor.wxMenus, menuList = _this.menuList;

                    //hxt.post({
                    //    url: hxt.config.link + 'wx/wxCSSend',
                    //    data: { account: _this.account, pwd: _this.pwd, wx_openId: _this.userid },
                    //    ok: function (res) {
                    //        if (res.code != 0) return hxt.error('登录失败：' + res.errmsg);
                           
                    //    }
                    //});







                    console.log(wxMenus.find(function (item) { return item.id==503 }),'菜单');
                    if (_this.optor.wxMenus.length == 0) return;
                    var createMenu = function (pId, list) {
                        var arr = wxMenus.filter(function (item, ix) {
                            return item.pId == pId && item.show != 1 && item.show != 99;
                        });
                        arr.forEach(function (item) {
                            var m = {
                                id: item.id,
                                pId: item.pId,
                                level: item.level,
                                name: item.name,
                                state: item.state,
                                icon: item.icon,
                                url: item.url,
                                show: item.show,
                                color: item.color,
                                children: []
                            };
                            createMenu(m.id, m.children);
                            list.push(m);
                        });
                    };
                    createMenu(1, menuList);
                    _this.menuList = menuList.sort(function (a, b) { return a.id - b.id; });
                    console.log('_this.menuList', _this.menuList);
                    console.log(hxt.config.link)
                },
                getUrl: function (menu) {
                    var _this = this;
                    return hxt.config.link + 'wx/go?state={0}&userid={1}'.formatStr(menu.state, this.optor.wx_openId);
                },
                itemclick: function (menu) {
                    var _this = this;
                    if (menu.state.toLocaleLowerCase().startsWith('ynupper')) {
                        if (_this.browser == 4) {
                            //小程序打开ABC
                            hxt.post({
                                url: hxt.config.link + 'weixin/abcParams',
                                data: { uiId: _this.optor.uiId, loginType: 'mini' },
                                ok: function (res) {
                                    if (res.code != 0) return hxt.alert(res.errmsg, '获取应用参数失败');

                                    var str = {
                                        appId: res.appId,
                                        path: res.path,
                                        envVersion: res.envVersion
                                    };
                                    var obj = _this.optor.encode(str, true).value;
                                    wx.miniProgram.navigateTo({
                                        url: '/pages/index/openMini?openEmbeddedMiniProgram=' + obj,
                                        success: function (res) {

                                        },
                                        fail: function (res) {
                                            hxt.alert(res.errMsg, '页面跳转失败');
                                        }
                                    });
                                }
                            });
                            return;
                        }
                    }
                    hxt.mask();
                },
                rightBtnClick: function () {
                    console.log(1111);
                }
            },
            components: {

            }
        };
    })(window.$jscript.fn);
</script>
<style>
    .van-icon-x {
        display: block;
        height: 28px;
        width: 28px;
        text-align: center;
        line-height: 28px !important;
        font-size: 18px !important;
        border-radius: 3px;
    }

    .color-card {
        background-color: #00AA95;
        color: #FFF;
    }

    .color-app {
        background-color: #4B7DFF;
        color: #FFF;
    }

    .bg-mauve {
        background-color: #9c26b0;
        color: #FFF;
    }

    .bg-jxhd {
        background-color: #02995B;
        color: #FFF;
    }
</style>